home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
rbsetnv1.zip
/
CHGPATH.C
< prev
next >
Wrap
Text File
|
1990-04-13
|
1KB
|
63 lines
/*
* chgpath.c
*
* Find the PATH variable, search for <pathname1> and if found, replace by
* <pathname2>. In any event, leave pathname2 in the path.
*
* Returned status:
* 0 OK (including case where nothing needs to be done)
* 1 bad arguments
*
*/
#include <io.h>
#include <string.h>
#include <stdlib.h>
void exit(int status) { _exit(status); }
#define writes(s,i) write(i,s,strlen(s));
main(int argc, char *argv[])
{
int len;
char *path, *pathname1, *pathname2, *str;
if( argc != 3) {
writes("Usage: inspath path_to_replace new_path\n",2);
exit(1);
} else {
len = strlen(argv[1]);
if(*(argv[1]+len-1) == ';') *(argv[1]+len-1) = '\0';
len = strlen(argv[2]);
if(*(argv[2]+len-1) == ';') *(argv[1]+len-1) = '\0';
pathname1 = strupr(argv[1]);
pathname2 = strupr(argv[2]);
path = getenv("PATH");
len = strlen(pathname1);
str = strupr(path);
while (str) {
str = strstr(str, pathname1);
if(!str) {
/* pathname1 not found - just tag pathname2 on the end */
writes(path,1);
writes(";",1)
writes(pathname2,1);
break;
} else if (*(str+len) == ';' || *(str+len) == '\0') {
/* found it - truncate before pathname1 */
*str = '\0';
writes(path,1);
writes(pathname2,1);
writes(str+len,1);
break;
} else {
/* found an incorrect match - keep looking */
str += len;
}
}
}
return(0);
}